package com.zuoye.day20;


import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class PersonTest {
    public static void main(String[] args) {
      List<Person> personList = new ArrayList<>();
      Person p1 = new Person("张学友",23,"男");
      Person p2 = new Person("张三",13,"女");
      Person p3 = new Person("班尼特",23,"男");
      Person p4 = new Person("八重神子",500,"女");

        personList.add(p1);
        personList.add(p2);
        personList.add(p3);
        personList.add(p4);


        System.out.println("====名字为3个字=====");
        personList.stream().filter(p -> p.getPerName().length() == 3).collect(Collectors.toList()).forEach(System.out::println);

        System.out.println("====前3个人=====");
        personList.stream().limit(3).collect(Collectors.toList()).forEach(System.out::println);

        System.out.println("===姓张的成员姓名====");
        personList.stream().filter(p -> p.getPerName().startsWith("张")).forEach(System.out::println);



      System.out.println("===不要前2个人====");
        personList.stream().skip(1).collect(Collectors.toList()).forEach(System.out::println);

      System.out.println("===根据姓氏分组====");

      Map<Character,List<Person>> collect = personList.stream().collect(Collectors.groupingBy(p->p.getPerName().charAt(0)));
      collect.forEach((k,v) -> System.out.println(k + ":" + v));
















    }
}
